import unittest
import json
import app
from api.loginAPI import loginAPI
from parameterized import parameterized

def build_data():
    json_file = app.base_path + "/data/data.json"
    test_data = []

    with open(json_file, encoding="utf-8") as f:
        json_data = json.load(f)

        for data in json_data:
            login_data = data.get("login_data")
            status_code = data.get("status_code")
            success = data.get("success")
            code = data.get("code")
            message = data.get("message")
            test_data.append((login_data, status_code, success, code, message))
    return test_data

class testLogin(unittest.TestCase):

    def setUp(self):
        self.loginAPI = loginAPI()


    def tearDown(self):
        pass


    @parameterized.expand(build_data())
    def test01_login(self, login_data, status_code, success, code, message):

        response = self.loginAPI.login(login_data)
        print(response.json())

        self.assertEqual(status_code, response.status_code)
        self.assertEqual(success, response.json().get("success"))
        self.assertEqual(code, response.json().get("code"))
        self.assertIn(message, response.json().get("message"))

